package com.cl.service.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cl.bean.Client;
import com.cl.dao.ClientDao;
import com.cl.service.ClientService;
import com.cl.utils.PageBean;

@Service
@Transactional
public class ClientServiceImpl implements ClientService {
	
	@Autowired
	private ClientDao clientDao;
	
	@Override
	public PageBean getPageBean(DetachedCriteria dc, int page, int limit) {
		int count = clientDao.getTotalCount(dc);
		PageBean pb = new PageBean(page, limit, count);
		List<Client> list = clientDao.getPageList(dc, pb.getStart(), pb.getPageSize());
		pb.setData(list);
		return pb;
	}

	@Override
	public List<Client> findByEid(int e_id) {
		DetachedCriteria dc = DetachedCriteria.forClass(Client.class);
		dc.add(Restrictions.eq("emp.e_id", e_id));
		return clientDao.finByDetachedCriteria(dc);
	}

}
